using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class UIADViewWnd : MonoBehaviour
{
	public enum ADViewType
	{
		None,
		Full,
		Get,
		Video,
		NotEnough,
		Tip,
		UseProp,
		Rate,
		GetRateRewards,
		Gift
	}

	private static string PATH = "UI/HallWindow";

	public GameObject fullWnd;

	public GameObject watchVideoWnd;

	public GameObject getPowerWnd;

	public GameObject notEnoughWnd;

	public GameObject tipWnd;

	public GameObject usePropWnd;

	public GameObject rateWnd;

	public GameObject getRateRewardWnd;

	public GameObject giftWnd;

	public Text txtPowerDesc;

	public Text txtChipsDesc;

	public Text txtGetPowerDesc;

	public Text txtGetItemNumber;

	public Text txtVideoTitle;

	public Text txtVideoDesc;

	public Text txtWatchVideoBtn;

	public Text txtTipWndDesc;

	public Text txtGiftTitle;

	public Image imgTipIcon;

	public Image imgGetItemIcon;

	public Image imgUsePropIcon;

	public Delegate0Args m_SureCallBack;

	public Delegate0Args m_CancelCallback;

	public Action onUseProp;

	public Action onClickGetItem;

	public Action onCloseGiftWnd;

	public Sprite[] spriteList;

	private static UIADViewWnd _adView;

	private bool m_RatingApp;

	public static Action OnRateThisAppDestroy;

	private void Start()
	{
	}

	private void Update()
	{
	}

	public static void Show(ADViewType type, int power = 0, int chips = 0)
	{
		if (type == ADViewType.Rate)
		{
			return;
		}
		if (_adView == null)
		{
			_adView = SupportTools.AddChild<UIADViewWnd>(GameManager.WindowCanvas.gameObject, PATH);
		}
		_adView.gameObject.SetActive(value: false);
		_adView.gameObject.SetActive(value: true);
		_adView.fullWnd.SetActive(value: false);
		_adView.watchVideoWnd.SetActive(value: false);
		_adView.getPowerWnd.SetActive(value: false);
		_adView.notEnoughWnd.SetActive(value: false);
		_adView.tipWnd.SetActive(value: false);
		_adView.usePropWnd.SetActive(value: false);
		_adView.rateWnd.SetActive(value: false);
		_adView.getRateRewardWnd.SetActive(value: false);
		_adView.giftWnd.SetActive(value: false);
		switch (type)
		{
			case ADViewType.Video:
				_adView.watchVideoWnd.gameObject.SetActive(value: true);
				_adView.txtVideoTitle.text = HOLocalizationConfiguration.GetValue(441);
				_adView.txtVideoDesc.text = HOLocalizationConfiguration.GetValue(442);
				break;
			case ADViewType.Full:
				_adView.fullWnd.gameObject.SetActive(value: true);
				break;
			case ADViewType.Get:
				_adView.getPowerWnd.gameObject.SetActive(value: true);
				if (power > 0)
				{
					_adView.imgGetItemIcon.sprite = LaunchUIController.instance.GetSpriteFromName("image_props1");
					_adView.txtGetPowerDesc.text = "获取体力！";
					_adView.txtGetItemNumber.text = power.ToString();
				}
				else if (chips > 0)
				{
					_adView.imgGetItemIcon.sprite = LaunchUIController.instance.GetSpriteFromName("Image_chip2");
					_adView.txtGetPowerDesc.text = "获取筹码！";
					_adView.txtGetItemNumber.text = chips.ToString();
				}
				break;
			case ADViewType.NotEnough:
				_adView.notEnoughWnd.gameObject.SetActive(value: true);
				break;
			case ADViewType.Tip:
				_adView.tipWnd.SetActive(value: true);
				break;
			case ADViewType.UseProp:
				_adView.usePropWnd.SetActive(value: true);
				break;
			case ADViewType.Rate:
				//_adView.rateWnd.SetActive(value: true);
				break;
			case ADViewType.GetRateRewards:
				_adView.getRateRewardWnd.SetActive(value: true);
				break;
			case ADViewType.Gift:
				_adView.giftWnd.SetActive(value: true);
				break;
		}
		_adView.txtPowerDesc.text = $"获取 {CommonConfig.CommonCfgInfo.videoPowerReward} 体力";
		_adView.txtChipsDesc.text = $"获取 {CommonConfig.CommonCfgInfo.videoChipReward} 筹码";
	}

	public static void ShowGetItem(int itemId, int count, Action onClick, bool autoTrigger = false)
	{
		Show(ADViewType.Get);
		ItemInfo info = ItemInfoMgr.GetInfo(itemId);
		string empty = string.Empty;
		empty = ((info.type != 4) ? info.icon : "Image_chip2");
		_adView.imgGetItemIcon.sprite = _adView.GetItemIconFromName(empty);
		_adView.txtGetItemNumber.text = count.ToString();
		_adView.txtGetPowerDesc.text = "获取 " + info.name + "!";
		_adView.getPowerWnd.GetComponent<UIGetItemWnd>().onClickOK = onClick;
		_adView.getPowerWnd.GetComponent<UIGetItemWnd>().autoTriggerClick = autoTrigger;
	}

	public Sprite GetItemIconFromName(string spriteName)
	{
		for (int i = 0; i < spriteList.Length; i++)
		{
			if (spriteList[i].name.Equals(spriteName))
			{
				return spriteList[i];
			}
		}
		return null;
	}

	public static void ShowTip(string content, Delegate0Args onSure = null, Delegate0Args onCancle = null, bool showIcon = false)
	{
		Show(ADViewType.Tip);
		_adView.txtTipWndDesc.text = content;
		_adView.m_SureCallBack = onSure;
		_adView.m_CancelCallback = onCancle;
		_adView.imgTipIcon.gameObject.SetActive(showIcon);
	}

	public static void ShowGift(string title, Action closeGift = null)
	{
		Show(ADViewType.Gift);
		_adView.txtGiftTitle.text = title;
		_adView.onCloseGiftWnd = closeGift;
	}

	public static void ConfirmUseProp(Sprite itemIcon, Action useProp)
	{
		Show(ADViewType.UseProp);
		_adView.imgUsePropIcon.sprite = itemIcon;
		_adView.onUseProp = useProp;
	}

	public void OnGetCurrency(int type)
	{
		/* AdManagerOld.instance.curAd.HideBanner();
		if (!AdManagerOld.instance.curAd.HasVideo())
		{
			ShowTip(HOLocalizationConfiguration.GetValue(179));
			return;
		} */
		switch (type)
		{
			case 0:
				if (ConstantData.physical >= 20)
				{
					Show(ADViewType.Full);
				}
				else
				{
					SDKTools.instance.PlayVedioRecoverPhysical();
				}
				break;
			case 1:
				SDKTools.instance.PlayVideoRecoverChips();
				break;
		}
	}

	public void GetFreeChipsFromSpin()
	{
		notEnoughWnd.SetActive(value: false);
		LaunchUIController.instance.OpenLucklyPanel();
	}

	public void WatchVideo()
	{
		SDKTools.instance.PlayVideoRecoverChips();
	}

	public void ClickTipWndOK()
	{
		if (m_SureCallBack != null)
		{
			m_SureCallBack();
		}
	}

	public void ClickTipWndCancle()
	{
		if (m_CancelCallback != null)
		{
			m_CancelCallback();
		}
	}

	public void ClickUseProp()
	{
		if (onUseProp != null)
		{
			onUseProp();
		}
	}

	public void CloseADView()
	{
		AdManagerOld.instance.curAd.HideBanner();
	}

	public void ClickRate()
	{
		m_RatingApp = true;
		PlayerPrefs.SetInt("RateInterval", 40);
		Application.OpenURL("https://play.google.com/store/apps/details?id=sports8.ball.pool.billiards.free&hl=en");
	}

	public void ClickCloseRate()
	{
		if (OnRateThisAppDestroy != null)
		{
			OnRateThisAppDestroy();
		}
	}

	public void OnApplicationPause(bool pause)
	{
		if (!pause && m_RatingApp)
		{
			AnimationTools componentInChildren = rateWnd.GetComponentInChildren<AnimationTools>();
			componentInChildren.Trigger("Hide");
			StartCoroutine(GiveRateRewards());
		}
	}

	private IEnumerator GiveRateRewards()
	{
		yield return new WaitForSeconds(0.5f);
		Show(ADViewType.GetRateRewards);
		ItemMgr.instance.AddItem(9);
		PlayerPrefs.SetInt("USE_CUE", 9);
		m_RatingApp = false;
	}

	public void ClickGetRateRewards()
	{
		if (OnRateThisAppDestroy != null)
		{
			PlayerPrefs.SetInt("StarRateKey", 1);
			OnRateThisAppDestroy();
		}
	}

	public void ClickGetItem()
	{
		if (onClickGetItem != null)
		{
			onClickGetItem();
		}
	}

	public void OpenGift()
	{
		AdManagerOld.instance.curAd.ShowGift("page_gift", 1);
		EternalNode.Instance.SendMessage("VedioPlayedCallback_Gift");
		_adView.giftWnd.SetActive(value: false);
	}

	public void CloseGift()
	{
		if (onCloseGiftWnd != null)
		{
			onCloseGiftWnd();
		}
	}

	public static bool EscapeGiftWnd()
	{
		if (_adView.giftWnd.activeInHierarchy)
		{
			_adView.giftWnd.GetComponentInChildren<AnimationTools>().Trigger("Hide");
			_adView.CloseGift();
			return true;
		}
		return false;
	}
}
